<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">保障性租赁住房</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="120px" :inline="true" size="mini">
                    <el-form-item label="区属名称:">
                        <div style="width: 170px">
                            <el-select v-model="form.qs" placeholder="请选择区属名称" clearable @change="onSearch">
                                <el-option v-for="item in qslist" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="产别类型:">
                        <div style="width: 170px">
                            <el-select v-model="form.cb" placeholder="请选择产别类型" clearable @change="onSearch">
                                <el-option v-for="item in cblist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                            <!-- <el-input v-model="form.cb" placeholder="请输入产别类型"></el-input> -->
                        </div>
                    </el-form-item>
                    <el-form-item label="权证类型:">
                        <div style="width: 170px">
                            <!-- <el-select v-model="form.qzlx" placeholder="请选择权证类型" clearable>
                                <el-option v-for="item in qzlxlist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select> -->
                            <el-input v-model="form.qzlx" placeholder="请输入权证类型" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width: 170px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="土地使用权类型:">
                        <div style="width: 170px">
                            <!-- <el-select v-model="form.tdsyqlx" placeholder="请选择土地使用权类型" clearable>
                                <el-option v-for="item in tdsyqlxlist" :key="item.code" :label="item.name"
                                    :value="item.code">
                                </el-option>
                            </el-select> -->
                            <el-input v-model="form.tdsyqlx" placeholder="请输入土地使用权类型" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="建筑面积:">
                        <div style="width: 170px">
                            <el-col :span="11">
                                <el-input v-model="form.jzmja" @keyup.enter.native="onSearch"></el-input>
                            </el-col>
                            <el-col class="line" :span="2"><span style="font-size: 12px">至</span></el-col>
                            <el-col :span="11">
                                <el-input v-model="form.jzmjb" @keyup.enter.native="onSearch"></el-input>
                            </el-col>
                        </div>
                    </el-form-item>
                    <el-form-item label="风貌建筑:">
                        <div style="width: 170px">
                            <el-select
                                v-model="form.fmjz"
                                placeholder="请选择是否为风貌建筑"
                                clearable
                                @change="onSearch1('fmjz', form.fmjz)"
                            >
                                <el-option v-for="item in sflist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="风貌保护等级:">
                        <div style="width: 170px">
                            <el-select
                                v-model="form.fmjzjb"
                                placeholder="请选择风貌建筑保护等级"
                                clearable
                                @change="onSearch"
                                :disabled="fmjzjbshow"
                            >
                                <el-option v-for="item in fmjzjblist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="文物保护:">
                        <div style="width: 170px">
                            <el-select
                                v-model="form.wwbh"
                                placeholder="请选择是否为文物保护"
                                clearable
                                @change="onSearch1('wwbh', form.wwbh)"
                            >
                                <el-option v-for="item in sflist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="文物保护级别:">
                        <div style="width: 170px">
                            <el-select
                                v-model="form.wwbhjb"
                                placeholder="请选择文物保护级别"
                                clearable
                                @change="onSearch"
                                :disabled="wwbhjbshow"
                            >
                                <el-option v-for="item in wwbhjblist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="小洋楼招商:">
                        <div style="width: 170px">
                            <el-select v-model="form.zsxyl" placeholder="请选择是否为小洋楼招商" clearable @change="onSearch">
                                <el-option v-for="item in sflist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width: 170px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房产状态:">
                        <div style="width: 170px">
                            <el-select v-model="form.fczt" placeholder="请选择房产状态" clearable @change="onSearch">
                                <el-option v-for="item in fcztlist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋性质:">
                        <div style="width: 170px">
                            <el-select v-model="form.fwyt" placeholder="请选择房屋性质" clearable @change="onSearch">
                                <el-option v-for="item in fwytlist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" class="searchcolor" icon="el-icon-refresh">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download" class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table
                :data="tableData"
                style="width: 100%"
                :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor"
                :row-class-name="tableRowClassName"
                :cell-style="tablecellColor"
                border
                :max-height="maxHeight"
                show-summary
                sum-text="合计"
                :summary-method="getSummaries"
            >
                <el-table-column prop="dabh" label="档案编号" align="center"> </el-table-column>
                <el-table-column prop="qs" label="区属" align="center" width="100"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="lh" label="楼号" align="center" width="60"> </el-table-column>
                <el-table-column prop="fwyt" label="房屋性质" align="center" width="100"> </el-table-column>
                <el-table-column prop="cb" label="产别" align="center" width="100"> </el-table-column>
                <el-table-column prop="zlc" label="总层数" align="center" width="80"> </el-table-column>
                <el-table-column prop="jzmj" label="建筑面积" align="center" width="100"> </el-table-column>
                <el-table-column prop="jizumj" label="计租面积" align="center" width="100"> </el-table-column>
                <el-table-column fixed="right" label="操作" width="160" align="center">
                    <template slot-scope="scope">
                        <router-link :to="{ name: 'detaillz', params: { id: scope.row.id } }" style="padding-right: 12px">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <router-link :to="{ name: 'addfj', params: { id: scope.row.id,dabh:scope.row.dabh,fwdz:scope.row.fwdz,qs:scope.row.qs } }" style="padding-right: 12px">
                            <!-- @click="addroom(scope.row)" -->
                            <el-button type="text" size="small">房间录入</el-button>
                        </router-link>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination
                    background
                    layout="total,prev, pager, next,jumper"
                    :total="total"
                    :current-page.sync="current"
                    :page-size="pageSize"
                    @current-change="handleCurrentChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import {
    buildlist, exportBuildlist,buildlisthj
} from '@/api/index';
import valueList from '@/components/common/valueList.vue';
export default {
    name: 'dalist',
    data() {
        return {
            fmjzjbshow: true,
            wwbhjbshow: true,
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                bzzf:'1',//是否保障性住房 1：是 0：否
                cb: '',
                cqdw: '',
                create_name: '',
                create_name_id: '',
                create_time: '',
                current: 0,
                dabh: '',
                dscs: '',
                dxcs: '',
                fmjz: '',
                fmjzjb: '',
                wwbh: '',
                wwbhjb: '',
                fwdz: '',
                fwjg: '',
                fwyt: '',
                fzrq: '',
                id: '',
                jdrq: '',
                jzmj: '',
                jzmja: '',
                jzmjb: '',
                jznd: '',
                jzxs: '',
                note: '',
                pageSize: 10,
                qs: '',
                qzlx: '',
                status_code: 0,
                tdsyqlx: '',
                tdsyqmj: '',
                update_name: '',
                update_name_id: '',
                update_time: '',
                yz: '',
                zlc: '',
                zsbh: '',
                zsxyl: '',
                fczt: '1'
                // gfdw: this.$store.getters.gfdw
            },
            tableData: [],
            qslist: valueList.qslist,
            cqdwlist: valueList.cqdwlist, //产权单位
            fwytlist: valueList.fwytlist, //房屋性质
            cblist: valueList.cblist, //产别
            qzlxlist: valueList.qzlxlist, //权证类型
            tdsyqlxlist: valueList.tdsyqlxlist, //土地使用权类型
            sflist: valueList.sflist, //是否列表
            gfdwlist: valueList.gfdwlist, //管房单位
            fcztlist: valueList.fcztlist, //房产状态
            fmjzjblist: valueList.fmjzjblist, //风貌建筑级别
            wwbhjblist: valueList.wwbhjblist, //文物保护级别
            maxHeight: null,
            hjje: {}
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.buildlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.buildlist(this.form);
            this.buildlisthj(this.form);
            console.log('搜索');
        },
        onSearch1(name, value) {
            console.log(value);
            if (name == 'fmjz') {
                console.log('fmjz', value);
                this.form.fmjzjb = '';
                this.fmjzjbshow = value == '是' ? false : true;
            } else if (name == 'wwbh') {
                console.log('wwbh', value);
                this.form.wwbhjb = '';
                this.wwbhjbshow = value == '是' ? false : true;
            }
            this.onSearch();
        },
        // 重置
        reSearch() {
            this.fmjzjbshow = true;
            this.wwbhjbshow = true;
            this.current = 1;
            this.form = {
                bzzf:'1',
                cb: '',
                cqdw: '',
                create_name: '',
                create_name_id: '',
                create_time: '',
                current: 0,
                dabh: '',
                dscs: '',
                dxcs: '',
                fmjz: '',
                fmjzjb: '',
                wwbh: '',
                wwbhjb: '',
                fwdz: '',
                fwjg: '',
                fwyt: '',
                fzrq: '',
                id: '',
                jdrq: '',
                jzmj: '',
                jzmja: '',
                jzmjb: '',
                jznd: '',
                jzxs: '',
                note: '',
                pageSize: 10,
                qs: '',
                qzlx: '',
                status_code: 0,
                tdsyqlx: '',
                tdsyqmj: '',
                update_name: '',
                update_name_id: '',
                update_time: '',
                yz: '',
                zlc: '',
                zsbh: '',
                zsxyl: '',
                fczt: '1'
            };
            this.buildlist(this.form);
            this.buildlisthj(this.form);
            console.log('搜索');
        },
        // 项目列表
        buildlist(data) {
            buildlist(data).then((res) => {
                if (res.code == 200) {
                    console.log(this.$store.getters.role);
                    console.log(this.$store.getters.yzydbnum);
                    console.log(this.$store.getters.dbnum3);
                    if (this.$store.getters.role == '10011') {
                        if (this.$store.getters.yzydbnum == 'true') {
                            alert(`预转已待办数量为${this.$store.getters.dbnum3},请尽快处理！！！`);
                            this.$store.commit('handleyzydbnum', false);
                        } else {
                            console.log(123);
                        }
                    }
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                    this.maxHeight = window.innerHeight - 440;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 项目合计
        buildlisthj(data) {
            buildlisthj(data).then((res) => {
                if (res.code == 200) {
                    this.hjje = res.data;
                    console.log(res.data);
                } else {
                    this.$message.error = '请联系管理人员！！';
                }
            });
        },
        // 导出列表
        downloadlist() {
            exportBuildlist(this.form).then((res) => {
                console.log(res);
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '楼幢导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res);
            });
        },
        // 合并计算某一列
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计';
                    return;
                }
                // 只对amount这一列进行总计核算。
                if (column.property === 'jizumj') {
                    sums[index] = this.hjje.jizumj;
                } else if (column.property === 'jzmj') {
                    sums[index] = this.hjje.jzmj;
                } else {
                    sums[index] = '---';
                }
            });
            return sums;
        }
    },
    mounted() {
        this.buildlist(this.form);
        this.buildlisthj(this.form)
    }
};
</script>
<style>
/* .el-table { overflow: visible !important; } */
.el-table__footer-wrapper tbody td.el-table__cell {
    font-weight: 600;
    background: rgb(246, 238, 217);
}

.tablestyle > .el-table {
    overflow: auto;
}

.tablestyle > .el-table .el-table__body-wrapper,
.tablestyle > .el-table .el-table__header-wrapper,
.tablestyle > .el-table .el-table__footer-wrapper {
    overflow: visible;
}

.tablestyle > .el-table::after {
    position: relative !important;
}
</style>
<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
